'use strict';

module.exports = app => {
    const {
        STRING,
        INTEGER,
        DATE,
        NOW
    } = app.Sequelize;

    const Sms = app.model.define('send_sms', {
        id: {
            type: INTEGER,
            primaryKey: true,
            autoIncrement: true
        },
        mobile: {
            type: STRING(30),
            field: 'mobile',
            allowNull: false,
        },
        verifyCode: {
            type: STRING(10),
            field: 'verify_code',
            allowNull: false,
        },
        createdAt: {
            type: DATE,
            field: 'created_at',
            allowNull: false,
            defaultValue: NOW,
        },
    }, {
        tableName: 'send_sms', //自定义标明
        freezeTableName: true, //固定表名，进行自定义
        timestamps: false, //禁止自动创建时间参数
        timezone: '+08:00',
    });

    Sms.findByMobile = async function (mobile) {
        return await this.findOne({
            where: {
                mobile
            },
        });
    };

    return Sms;
};